package com.example.springboot.mapper;

import com.example.springboot.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("SELECT * from sys_user")
    List<User> findAll();

    @Insert("insert into sys_user(username,user_number,gender,phone,email,password,role_id) " +
            "VALUES (#{username},#{userNumber},#{gender},#{phone},#{email},#{password},#{roleId});")
    int insert(User user);

    int update(User user);

    @Delete("delete from sys_user where id = #{id}")
    Integer deleteById(@Param("id")Integer id);

    @Select("select * from sys_user where username like concat('%',#{username},'%') limit #{pageNum},#{pageSize}")
    List<User> selectPage(Integer pageNum, Integer pageSize, String username);

    @Select("select count(*) from sys_user where username like concat('%',#{username},'%')")
    Integer selectTotal(String username);

    @Select("select id from sys_user where username = #{username}")
    Integer selectId(String username);

    @Select("select username from sys_user where id = #{id}")
    String selectName(Integer id);

}
